import os
import sys
from tkinter import filedialog, Tk


class FilePathLoader:

    def get_any_file_path(self, file_path=''):
        ENV_EXCLUSION = ['COLAB_GPU', 'RUNPOD_POD_ID']
        if (
                not any(var in os.environ for var in ENV_EXCLUSION)
                and sys.platform != 'darwin'
        ):
            current_file_path = file_path
            initial_dir, initial_file = get_dir_and_file(file_path)

            root = Tk()
            root.wm_attributes('-topmost', 1)
            root.withdraw()
            file_path = filedialog.askopenfilename(
                initialdir=initial_dir,
                initialfile=initial_file,
            )
            root.destroy()

            if file_path == '':
                file_path = current_file_path

        return file_path


def get_dir_and_file(file_path):
    dir_path, file_name = os.path.split(file_path)
    return (dir_path, file_name)